<div id="form"></div>
<script>
var grid;
var frm=$("#form").ajajform({
	header: null,
	submit: {
		url: '{{action}}',
		value: "{{!!save}}",
		ajaj: true,
		params: {mode: "save",ajaj: 1}
	},
	footerButtons: [
		{value: "{{!add}}",click: function() {grid.ajajform_grid("insertRow",null,{rowClass: "role",cells: ["","","",""]});}},
		{value: "{{!del}}",click: function() {grid.ajajform_grid("deleteSelectedRownums");}}
	]
});
grid=frm.ajajform("insertWidget",null,null,{
	type: "grid",
	title: "{{!title}}",
	name: "roles",
	mode: "form-edit-full",
	rowSelection: true,
	rowClasses: [{
		name:"role",
		columns: [
			{name: "code", label: "{{!code}}", width: 250},
			{name: "name", label: "{{!name}}", width: 450}
		]
	}]
});
var roles={{JSON:all_roles}};
for (var i=0;i<roles.length;i++) {
	var r=roles[i];
	grid.ajajform_grid("insertRow",null,{rowClass: "role",cells:[r.code,r.name],id:r.id});
}
</script>

